<template>
  <el-dialog v-model="show" title="导入表格" width="500">
    <el-form :model="form" class="demo-form-inline">
      <el-form-item label="期号">
        <el-input v-model="form.qihao" placeholder="请输入期号" clearable />
      </el-form-item>
      <el-form-item label="模板">
        <el-select v-model="form.importConfigId" placeholder="请选择模板">
          <el-option
            v-for="item in options"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          >
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="文件">
        <yuUpload
          @update:modelValue="uploadOk"
          :data="form"
          :disabled="!form.qihao || !form.importConfigId"
          url="/admin/ghOrderCollect/importExcel"
        />
      </el-form-item>
    </el-form>
  </el-dialog>
</template>

<script setup>
const emit = defineEmits(['refreshDataList']);
const show = ref(false);
const form = ref({});
const init = () => {
  show.value = true;
};

const options = ref([
  {
    label: "1",
    value: 1,
  },
]);

const getModalList = () => {
  let url = "/admin/importConfig/getList";
  http({
    url: http.adornUrl(url),
    method: "get",
  }).then((res) => {
    console.log(res);
    options.value = res.data.map((item) => {
      return {
        label: item.name,
        value: item.id,
      };
    });
  });
};

getModalList();

const uploadOk = (res) => {
  console.log(res);
  if (res.success) {
    ElMessage({
      message: "导入成功！",
      type: "success",
    });
    emit('refreshDataList')
  } else {
    ElMessage({
      message: "导入失败！" + res.msg,
      type: "Error",
    });
  }
  show.value = false;
};

defineExpose({ init });
</script>
